import { defineStore } from 'pinia'
import fetch from '@/common/utils/http'
import mcGetCache from '@/common/utils/mc-get-cache'

export interface CallCenterIvr {
  cacheSign: boolean
  selectCache: Record<string, unknown>
  voiceTransfer: Record<string, unknown>
  ivrData: Record<string, unknown>
  hideNav: boolean
}
export default defineStore('callCenterIvr', {
  state: () =>
    ({
      cacheSign: false,
      selectCache: {},
      voiceTransfer: {},
      ivrData: {},
      hideNav: false
    } as CallCenterIvr),
  getters: {},
  actions: {
    toggleNav(status: boolean) {
      this.hideNav = status
    },
    setIvrData(data: any) {
      this.ivrData = data
    },
    setSelCache({ key, value }: any) {
      this.selectCache[key] = value
    },
    setCacheSign(sign: boolean) {
      this.cacheSign = sign
    },
    setVoiceTransfer(data: any) {
      this.voiceTransfer = data
    },
    async IvrCommonAction(param: object) {
      return fetch(param)
    },
    async getNodeCache() {
      // 服务号列表 语音库列表 时间条件缓存
      const res = await Promise.all([
        mcGetCache.$getCache('groupCache'),
        mcGetCache.$getCache('voiceLibrary'),
        mcGetCache.$getCache('serviceTime'),
        mcGetCache.$getCache('userCache')
      ])
      ;['queueList', 'voiceLibraryList', 'timeConditionList', 'userList'].forEach((i: any, m: number) => {
        this.setSelCache({ key: i, value: res[m] })
      })
    },
    async setSelectCache({ key, value }: any) {
      this.setSelCache({ key, value })
    }
  }
})
